#!/usr/bin/env python

#	UPDATE A STANDARTIZED DATA VECTOR IN A WAY THAT A LIST OF MAC ADDRESSES
#	AND THEIR SIGNAL STRENGTHS IS EXTENDED TO CONTAIN ALL MAC ADDRESSES 
#	FROM ABSOLUTE VECTOR (THE ORDERED VALUE FOR THE SIGNAL STRENGTH FOR 
#	SUCH ADDITIONAL MAC ADDRESSES IS EQUAL TO 0).
def Absolutify(v, av):

	newV = []

	for mac in av:
		newV.append((mac, 0))

	i = 0

	while i < len(v[2]):
		newV[ReturnIndexOfMac(v[2][i], newV)] = (v[2][i], v[3][i])
		i = i + 1

	return (v[0], v[1], newV)

#	RETURNS AN INDEX OF THE ELEMENT IN THE VECTOR v OF TYPE (MAC ADDRESS, 
#	ORDERED SIGNAL STRENGTH) THAT HAS ITS MAC ADDRESS EQUAL TO macId. NOTE:
#	RETURNS -1 IN CASE THE ELEMENT IN NOT FOUND OR MAC ADDRESS IS NOT 
#	PRESENT IN ANY ELEMENT OF THE VECTOR v. THIS NORMALLY SHOULD NOT HAPPEN
#	BECAUSE THIS FUNCTION IS USED ONLY FOR THE ABSOLUTE VECTOR THAT DOES
#	CONTAIN ALL MAC IDS.
def ReturnIndexOfMac(macId, v):

	for mac, order in v:
		if mac == macId:
			return v.index((mac, order))

	return -1

#	BUILD A VECTOR (SO CALLED ABSOLUTE VECTOR) THAT CONTAINS ALL MAC 
#	ADDRESSES SEEN EITHER IN THE NEW SCAN OR IN THE PREVIOUS REALATED 
#	SCANS.
def BuildAbsoluteVector(data, uniqueMacs):

	av = []

	for row in data:
		for mac in row[2]:
			if av.count(mac) == 0:
				av.append(mac)

	for uMac in uniqueMacs:
		if av.count(uMac) == 0:
				av.append(uMac)

	return av

#	GET READ OF THE DUPLICATES IN THE SCANS LIST. RETURNS A NEW SCAN LIST
#	WITH NO REPEATING ELEMENTS.
def RemoveDuplicatesFromScans(scans):

	uScans = []

	for s in scans:
		if not HasScan(uScans, s[0]):
			uScans.append(s)
		
	return uScans

#	DETERMINES IF THE SCAN (OR MORE ACCURATELY SCAN TIME EQUAL TO sTime) IS
#	PRESENT IN THE LIST OF UNIQUE SCANS.
def HasScan(uScans, sTime):

	for s in uScans:
		if s[0] == sTime:
			return True

	return False
